home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / lib / hanning.pro < prev    next >
Text File  |  1997-07-08  |  2KB  |  69 lines

  1. ; $Id: hanning.pro,v 1.3 1997/01/15 03:11:50 ali Exp $
  2. ;
  3. ; Copyright (c) 1987-1997, Research Systems, Inc.  All rights reserved.
  4. ;    Unauthorized reproduction prohibited.
  5. ;
  6. function Hanning, N1, N2, Alpha=alpha ;1D or 2D Hanning/Hamming window function
  7. ;+
  8. ; NAME:
  9. ;    HANNING
  10. ;
  11. ; PURPOSE:
  12. ;    Window function for Fourier Transform filtering.  May be used
  13. ;        for both the Hanning and Hamming windows.
  14. ;
  15. ; CATEGORY:
  16. ;    Signal, image processing.
  17. ;
  18. ; CALLING SEQUENCE:
  19. ;    Result = HANNING(N1) ;For 1 dimension.
  20. ;
  21. ;    Result = HANNING(N1, N2) ;For 2 dimensions.
  22. ;
  23. ; INPUTS:
  24. ;    N1:    The number of columns of the result.
  25. ;
  26. ;    N2:    The number of rows of the result.
  27. ;
  28. ; Keyword Parameters:
  29. ;    Alpha = width parameter of generalized Hamming window.  Alpha
  30. ;        must be in the range of 0.5 to 1.0.  If Alpha = 0.5,
  31. ;        the default, the function is called the "Hanning" window.
  32. ;        If Alpha = 0.54, the result is called the "Hamming" window.
  33. ;
  34. ; OUTPUTS:
  35. ;    Result(i) = 1/2 [1 - COS(2 PI i / (N-1)]
  36. ;
  37. ;    For two dimensions, the result is the same except that "i" is replaced
  38. ;    with "i*j", where i and j are the row and column subscripts.
  39. ;
  40. ; COMMON BLOCKS:
  41. ;    None.
  42. ;
  43. ; SIDE EFFECTS:
  44. ;    None.
  45. ;
  46. ; RESTRICTIONS:
  47. ;    None.
  48. ;
  49. ; PROCEDURE:
  50. ;    Straightforward.
  51. ;
  52. ; MODIFICATION HISTORY:
  53. ;    DMS, May, 1987.
  54. ;    DMS, Jan, 1994. Added generalized width parameter.
  55. ;-
  56.  
  57. on_error,2                              ;Return to caller if an error occurs
  58. if N_elements(alpha) le 0 then alpha = 0.5
  59. a = 2 * !pi / (N1 -1)            ;scale factor
  60. If n_params(0) eq 1 then begin        ;1d?
  61.     return, (alpha-1.) * cos(findgen(N1)*a) + alpha
  62.    endif else begin            ;2d case
  63.     b = 2 * !pi / (n2-1)        ;dim 2 scale fact
  64.     row = (alpha-1.) * cos(findgen(n1)*a) + alpha ;One row
  65.     col = (alpha-1.) * cos(findgen(n2)*b) + alpha ;One column
  66.     RETURN,(row # col)
  67.    endelse
  68. end
  69.